/**
 * 
 */
package com.youxin.cpcenter.pt.service;

import rx.Observable;
import rx.Subscriber;

/**
 * @author yingde.cao
 * @date 2017年12月22日
 * @version 1.0
 */
public class CallService {
	public static void subscribe(){
		
		Observable.create(new Observable.OnSubscribe<Integer>() {
		    @Override
		    public void call(Subscriber<? super Integer> observer) {
		        try {
		            if (!observer.isUnsubscribed()) {
		                for (int i = 1; i < 5; i++) {
		                    observer.onNext(i);
		                }
		                observer.onCompleted();
		            }
		        } catch (Exception e) {
		            observer.onError(e);
		        }
		    }
		 } ).subscribe(new Subscriber<Integer>() {
		        @Override
		        public void onNext(Integer item) {
		            System.out.println("Next: " + item);
		        }

		        @Override
		        public void onError(Throwable error) {
		            System.err.println("Error: " + error.getMessage());
		        }

		        @Override
		        public void onCompleted() {
		            System.out.println("Sequence complete.");
		        }
		    });

	}
}
